using System;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Collections.Generic;
using System.Reflection;

namespace Xdt.Archives.Data
{
  /// <summary>
  /// Archives Data Object Class
  /// </summary>
  public partial class DOArchives
  {
    #region Class Constant declarations
    		/// <summary>
		/// The Table Column for the Archives ArchiveId
		/// </summary>
		public const string RowArchiveId = "Archive_ID";

		/// <summary>
		/// The Table Column for the Archives CreatedByUserId
		/// </summary>
		public const string RowCreatedByUserId = "CreatedByUser_ID";

		/// <summary>
		/// The Table Column for the Archives ArchiveDate
		/// </summary>
		public const string RowArchiveDate = "ArchiveDate";

		/// <summary>
		/// The Table Column for the Archives ArchiveStatus
		/// </summary>
		public const string RowArchiveStatus = "ArchiveStatus";

		/// <summary>
		/// The Table Column for the Archives DivisionName
		/// </summary>
		public const string RowDivisionName = "DivisionName";

		/// <summary>
		/// The Table Column for the Archives DepartmentName
		/// </summary>
		public const string RowDepartmentName = "DepartmentName";

		/// <summary>
		/// The Table Column for the Archives AttachedFile
		/// </summary>
		public const string RowAttachedFile = "AttachedFile";

		/// <summary>
		/// The Table Column for the Archives Comments
		/// </summary>
		public const string RowComments = "Comments";

		/// <summary>
		/// The Table Column for the Archives DestructionDate
		/// </summary>
		public const string RowDestructionDate = "DestructionDate";

		/// <summary>
		/// The Table Column for the Archives Shred
		/// </summary>
		public const string RowShred = "Shred";

		/// <summary>
		/// The Table Column for the Archives NoShredReason
		/// </summary>
		public const string RowNoShredReason = "NoShredReason";

		/// <summary>
		/// The Table Column for the Archives CurrentLocation
		/// </summary>
		public const string RowCurrentLocation = "CurrentLocation";

		/// <summary>
		/// The Table Column for the Archives DeliveryCollection
		/// </summary>
		public const string RowDeliveryCollection = "DeliveryCollection";

		/// <summary>
		/// The Table Column for the Archives DueDate
		/// </summary>
		public const string RowDueDate = "DueDate";

		/// <summary>
		/// The Table Column for the Archives ApprovedUserId
		/// </summary>
		public const string RowApprovedUserId = "ApprovedUser_ID";

		/// <summary>
		/// The Table Column for the Archives ApprovedDate
		/// </summary>
		public const string RowApprovedDate = "ApprovedDate";

		/// <summary>
		/// The Table Column for the Archives ReceivedbyUserId
		/// </summary>
		public const string RowReceivedbyUserId = "ReceivedbyUser_ID";

		/// <summary>
		/// The Table Column for the Archives ReceivedDate
		/// </summary>
		public const string RowReceivedDate = "ReceivedDate";

		/// <summary>
		/// The Table Column for the Archives ClosedByUserId
		/// </summary>
		public const string RowClosedByUserId = "ClosedByUser_ID";

		/// <summary>
		/// The Table Column for the Archives ClosedDate
		/// </summary>
		public const string RowClosedDate = "ClosedDate";


#region Stored Procedures
private const string m_StoredProcedureConstCreate = "spArchives_Create";
private const string m_StoredProcedureConstDelete = "spArchives_Delete";
private const string m_StoredProcedureConstRetrieve = "spArchives_Retrieve";
private const string m_StoredProcedureConstRetrieveall = "spArchives_Retrieveall";
private const string m_StoredProcedureConstUpdate = "spArchives_Update";
#endregion
    
    
    #endregion

    #region Class Variable declarations
    	#region DO Variables
		private int m_ArchiveId;
		private long m_CreatedByUserId;
		private DateTime m_ArchiveDate;
		private string m_ArchiveStatus;
		private string m_DivisionName;
		private string m_DepartmentName;
		private byte[] m_AttachedFile;
		private string m_Comments;
		private DateTime m_DestructionDate;
		private bool m_Shred;
		private string m_NoShredReason;
		private string m_CurrentLocation;
		private string m_DeliveryCollection;
		private DateTime m_DueDate;
		private long m_ApprovedUserId;
		private DateTime m_ApprovedDate;
		private long m_ReceivedbyUserId;
		private DateTime m_ReceivedDate;
		private long m_ClosedByUserId;
		private DateTime m_ClosedDate;
	#endregion
    
	#region Default Variables
	private SQLDataObject sqlData;
	private List<DOArchives> m_Archivess = new List<DOArchives>();
	#endregion
	
    #endregion

    #region Class Constructors & Destructors
    /// <summary>
    /// Class Constructor
    /// </summary>
    public DOArchives() { }
    #endregion

    #region Class Properties
    #region DO Properties
		/// <summary>
		/// ArchiveId
		/// </summary>
		/// <remarks>
		/// This property contains the Archives ArchiveId
		/// </remarks>
		public int ArchiveId
		{
			get { return (this.m_ArchiveId); }
			set { this.m_ArchiveId = value; }
		}

		/// <summary>
		/// CreatedByUserId
		/// </summary>
		/// <remarks>
		/// This property contains the Archives CreatedByUserId
		/// </remarks>
		public long CreatedByUserId
		{
			get { return (this.m_CreatedByUserId); }
			set { this.m_CreatedByUserId = value; }
		}

		/// <summary>
		/// ArchiveDate
		/// </summary>
		/// <remarks>
		/// This property contains the Archives ArchiveDate
		/// </remarks>
		public DateTime ArchiveDate
		{
			get { return (this.m_ArchiveDate); }
			set { this.m_ArchiveDate = value; }
		}

		/// <summary>
		/// ArchiveStatus
		/// </summary>
		/// <remarks>
		/// This property contains the Archives ArchiveStatus
		/// </remarks>
		public string ArchiveStatus
		{
			get { return (this.m_ArchiveStatus); }
			set { this.m_ArchiveStatus = value; }
		}

		/// <summary>
		/// DivisionName
		/// </summary>
		/// <remarks>
		/// This property contains the Archives DivisionName
		/// </remarks>
		public string DivisionName
		{
			get { return (this.m_DivisionName); }
			set { this.m_DivisionName = value; }
		}

		/// <summary>
		/// DepartmentName
		/// </summary>
		/// <remarks>
		/// This property contains the Archives DepartmentName
		/// </remarks>
		public string DepartmentName
		{
			get { return (this.m_DepartmentName); }
			set { this.m_DepartmentName = value; }
		}

		/// <summary>
		/// AttachedFile
		/// </summary>
		/// <remarks>
		/// This property contains the Archives AttachedFile
		/// </remarks>
		public byte[] AttachedFile
		{
			get { return (this.m_AttachedFile); }
			set { this.m_AttachedFile = value; }
		}

		/// <summary>
		/// Comments
		/// </summary>
		/// <remarks>
		/// This property contains the Archives Comments
		/// </remarks>
		public string Comments
		{
			get { return (this.m_Comments); }
			set { this.m_Comments = value; }
		}

		/// <summary>
		/// DestructionDate
		/// </summary>
		/// <remarks>
		/// This property contains the Archives DestructionDate
		/// </remarks>
		public DateTime DestructionDate
		{
			get { return (this.m_DestructionDate); }
			set { this.m_DestructionDate = value; }
		}

		/// <summary>
		/// Shred
		/// </summary>
		/// <remarks>
		/// This property contains the Archives Shred
		/// </remarks>
		public bool Shred
		{
			get { return (this.m_Shred); }
			set { this.m_Shred = value; }
		}

		/// <summary>
		/// NoShredReason
		/// </summary>
		/// <remarks>
		/// This property contains the Archives NoShredReason
		/// </remarks>
		public string NoShredReason
		{
			get { return (this.m_NoShredReason); }
			set { this.m_NoShredReason = value; }
		}

		/// <summary>
		/// CurrentLocation
		/// </summary>
		/// <remarks>
		/// This property contains the Archives CurrentLocation
		/// </remarks>
		public string CurrentLocation
		{
			get { return (this.m_CurrentLocation); }
			set { this.m_CurrentLocation = value; }
		}

		/// <summary>
		/// DeliveryCollection
		/// </summary>
		/// <remarks>
		/// This property contains the Archives DeliveryCollection
		/// </remarks>
		public string DeliveryCollection
		{
			get { return (this.m_DeliveryCollection); }
			set { this.m_DeliveryCollection = value; }
		}

		/// <summary>
		/// DueDate
		/// </summary>
		/// <remarks>
		/// This property contains the Archives DueDate
		/// </remarks>
		public DateTime DueDate
		{
			get { return (this.m_DueDate); }
			set { this.m_DueDate = value; }
		}

		/// <summary>
		/// ApprovedUserId
		/// </summary>
		/// <remarks>
		/// This property contains the Archives ApprovedUserId
		/// </remarks>
		public long ApprovedUserId
		{
			get { return (this.m_ApprovedUserId); }
			set { this.m_ApprovedUserId = value; }
		}

		/// <summary>
		/// ApprovedDate
		/// </summary>
		/// <remarks>
		/// This property contains the Archives ApprovedDate
		/// </remarks>
		public DateTime ApprovedDate
		{
			get { return (this.m_ApprovedDate); }
			set { this.m_ApprovedDate = value; }
		}

		/// <summary>
		/// ReceivedbyUserId
		/// </summary>
		/// <remarks>
		/// This property contains the Archives ReceivedbyUserId
		/// </remarks>
		public long ReceivedbyUserId
		{
			get { return (this.m_ReceivedbyUserId); }
			set { this.m_ReceivedbyUserId = value; }
		}

		/// <summary>
		/// ReceivedDate
		/// </summary>
		/// <remarks>
		/// This property contains the Archives ReceivedDate
		/// </remarks>
		public DateTime ReceivedDate
		{
			get { return (this.m_ReceivedDate); }
			set { this.m_ReceivedDate = value; }
		}

		/// <summary>
		/// ClosedByUserId
		/// </summary>
		/// <remarks>
		/// This property contains the Archives ClosedByUserId
		/// </remarks>
		public long ClosedByUserId
		{
			get { return (this.m_ClosedByUserId); }
			set { this.m_ClosedByUserId = value; }
		}

		/// <summary>
		/// ClosedDate
		/// </summary>
		/// <remarks>
		/// This property contains the Archives ClosedDate
		/// </remarks>
		public DateTime ClosedDate
		{
			get { return (this.m_ClosedDate); }
			set { this.m_ClosedDate = value; }
		}
		#endregion
    
	#region Default Properties
	public List<DOArchives> Archivess
	{
	  get { return m_Archivess; }
	  set { m_Archivess = value; }
	}    
	#endregion
	
    #endregion

    #region Class Methods
    public bool Retrieve()
    {
      sqlData = new SQLDataObject();
      DataSet resultDS = sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieve + " @" + RowArchive_ID + "=" + this.Archive_ID);
      return SetClassPropertiesFromDataSet(resultDS);
    }

    public bool RetrieveAll()
    {
      sqlData = new SQLDataObject();
      string sVariables = sqlData.GetVariables(this);

      DataSet resultDS = sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieveall + " " + sVariables);
      return SetClassPropertiesListFromDataSet(resultDS);
    }

    public bool Create()
    {
      bool success = false;
      sqlData = new SQLDataObject();
      string sVariables = sqlData.GetVariables(this);

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstCreate + " " + sVariables);

      return success;
    }

    public bool Update()
    {
      bool success = false;
      sqlData = new SQLDataObject();

      string sVariables = sqlData.GetVariables(this);

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstUpdate + " " + sVariables);

      return success;
    }

    private bool SetClassPropertiesFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
					if (dr[RowArchiveId].ToString() != "")
			this.ArchiveId = int.Parse(dr[RowArchiveId].ToString());

		if (dr[RowCreatedByUserId].ToString() != "")
			this.CreatedByUserId = long.Parse(dr[RowCreatedByUserId].ToString());

		if (dr[RowArchiveDate].ToString() != "")
			this.ArchiveDate = DateTime.Parse(dr[RowArchiveDate].ToString());

		if (dr[RowArchiveStatus].ToString() != "")
			this.ArchiveStatus = dr[RowArchiveStatus].ToString();

		if (dr[RowDivisionName].ToString() != "")
			this.DivisionName = dr[RowDivisionName].ToString();

		if (dr[RowDepartmentName].ToString() != "")
			this.DepartmentName = dr[RowDepartmentName].ToString();

		if (dr[RowAttachedFile].ToString() != "")
			this.AttachedFile = byte[].Parse(dr[RowAttachedFile].ToString());

		if (dr[RowComments].ToString() != "")
			this.Comments = dr[RowComments].ToString();

		if (dr[RowDestructionDate].ToString() != "")
			this.DestructionDate = DateTime.Parse(dr[RowDestructionDate].ToString());

		if (dr[RowShred].ToString() != "")
			this.Shred = bool.Parse(dr[RowShred].ToString());

		if (dr[RowNoShredReason].ToString() != "")
			this.NoShredReason = dr[RowNoShredReason].ToString();

		if (dr[RowCurrentLocation].ToString() != "")
			this.CurrentLocation = dr[RowCurrentLocation].ToString();

		if (dr[RowDeliveryCollection].ToString() != "")
			this.DeliveryCollection = dr[RowDeliveryCollection].ToString();

		if (dr[RowDueDate].ToString() != "")
			this.DueDate = DateTime.Parse(dr[RowDueDate].ToString());

		if (dr[RowApprovedUserId].ToString() != "")
			this.ApprovedUserId = long.Parse(dr[RowApprovedUserId].ToString());

		if (dr[RowApprovedDate].ToString() != "")
			this.ApprovedDate = DateTime.Parse(dr[RowApprovedDate].ToString());

		if (dr[RowReceivedbyUserId].ToString() != "")
			this.ReceivedbyUserId = long.Parse(dr[RowReceivedbyUserId].ToString());

		if (dr[RowReceivedDate].ToString() != "")
			this.ReceivedDate = DateTime.Parse(dr[RowReceivedDate].ToString());

		if (dr[RowClosedByUserId].ToString() != "")
			this.ClosedByUserId = long.Parse(dr[RowClosedByUserId].ToString());

		if (dr[RowClosedDate].ToString() != "")
			this.ClosedDate = DateTime.Parse(dr[RowClosedDate].ToString());
          }
          success = true;
        }
      }
      return success;
    }

    private bool SetClassPropertiesListFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
            DOArchives Archives = new DOArchives();
			
					if (dr[RowArchiveId].ToString() != "")
			Archives.ArchiveId = int.Parse(dr[RowArchiveId].ToString());

		if (dr[RowCreatedByUserId].ToString() != "")
			Archives.CreatedByUserId = long.Parse(dr[RowCreatedByUserId].ToString());

		if (dr[RowArchiveDate].ToString() != "")
			Archives.ArchiveDate = DateTime.Parse(dr[RowArchiveDate].ToString());

		if (dr[RowArchiveStatus].ToString() != "")
			Archives.ArchiveStatus = dr[RowArchiveStatus].ToString();

		if (dr[RowDivisionName].ToString() != "")
			Archives.DivisionName = dr[RowDivisionName].ToString();

		if (dr[RowDepartmentName].ToString() != "")
			Archives.DepartmentName = dr[RowDepartmentName].ToString();

		if (dr[RowAttachedFile].ToString() != "")
			Archives.AttachedFile = byte[].Parse(dr[RowAttachedFile].ToString());

		if (dr[RowComments].ToString() != "")
			Archives.Comments = dr[RowComments].ToString();

		if (dr[RowDestructionDate].ToString() != "")
			Archives.DestructionDate = DateTime.Parse(dr[RowDestructionDate].ToString());

		if (dr[RowShred].ToString() != "")
			Archives.Shred = bool.Parse(dr[RowShred].ToString());

		if (dr[RowNoShredReason].ToString() != "")
			Archives.NoShredReason = dr[RowNoShredReason].ToString();

		if (dr[RowCurrentLocation].ToString() != "")
			Archives.CurrentLocation = dr[RowCurrentLocation].ToString();

		if (dr[RowDeliveryCollection].ToString() != "")
			Archives.DeliveryCollection = dr[RowDeliveryCollection].ToString();

		if (dr[RowDueDate].ToString() != "")
			Archives.DueDate = DateTime.Parse(dr[RowDueDate].ToString());

		if (dr[RowApprovedUserId].ToString() != "")
			Archives.ApprovedUserId = long.Parse(dr[RowApprovedUserId].ToString());

		if (dr[RowApprovedDate].ToString() != "")
			Archives.ApprovedDate = DateTime.Parse(dr[RowApprovedDate].ToString());

		if (dr[RowReceivedbyUserId].ToString() != "")
			Archives.ReceivedbyUserId = long.Parse(dr[RowReceivedbyUserId].ToString());

		if (dr[RowReceivedDate].ToString() != "")
			Archives.ReceivedDate = DateTime.Parse(dr[RowReceivedDate].ToString());

		if (dr[RowClosedByUserId].ToString() != "")
			Archives.ClosedByUserId = long.Parse(dr[RowClosedByUserId].ToString());

		if (dr[RowClosedDate].ToString() != "")
			Archives.ClosedDate = DateTime.Parse(dr[RowClosedDate].ToString());

            this.Archivess.Add(Archives);
          }
          success = true;
        }
      }
      return success;
    }
    #endregion

    #region Class Support Methods
    #endregion
  }
}
